***************************************
***************************************
* Analysis (cross-sectional data set)
***************************************
***************************************
cap log close

use "${FINALDATA}\immo.dta", clear
gen multlist = infocount > 1 & !missing(infocount)
global ifnotlastmonth "if monat != monthly("2015 10", "YM")" 
 

***************************************************
* Code variables
***************************************************
replace zimmer_cont = . if zimmer == .
gen zimmer_cont2 = zimmer_cont^2

gen baujahr_adopt = baujahr_kat
recode baujahr_adopt ( 1930 1950 1960 1970 = 1900) (1995 1990 = 1977) (2014 2008 = 2002)
gen modern_adopt = modern_kat
recode modern_adopt (1990 = 1977) (2015 2008 = 2002)



if ($LOGTIME == 1) log using "${LOG}/${DATE}_analyses_disclosure.log", replace
**************
**************
* Analyses
**************
**************

global merkat baujahr_adopt modern_adopt objektkat qualitaet heizart
global merkat_i ""
foreach x of global merkat {
	global merkat_i $merkat_i i.`x' 
}
global merkont grundflaeche wohnflaeche zimmer_cont grundflaeche2 wohnflaeche2 

gen missing_test = 0
foreach var of global merkont {
	replace missing_test = 1 if missing(`var')
}



***
* Table 3: OLS Regression Results for Linear Probability Model
***

* recode variables (for better readability)
replace grundflaeche = grundflaeche / 1000
replace grundflaeche2 = grundflaeche2 / 1000^2
replace wohnflaeche= wohnflaeche / 100
replace wohnflaeche2 = wohnflaeche2 / 100^2

xtset plz
xtreg epc $merkat_i $merkont ib1.objektzus ib5.anbietertyp##postmai ${ifnotlastmonth}, fe
est sto disclosure

estout disclosure, ///
	cells("b(star label(Coeff.) fmt(%12.2gc)) se(label(Std. Err.) fmt(%12.2gc))") ///
	starlevels(* 0.05 ** 0.01) ///
	stats(N, fmt(%12.0fc)) ///
	nobaselevels ///
	varlabels( ///
	1900.baujahr_adopt "1900-1976" 1977.baujahr_adopt "1977-2002" 2002.baujahr_adopt "2002-2015" 9999.baujahr_adopt "n.a." ///
	1900.modern_adopt "1900-1976" 1977.modern_adopt "1977-2001" 2002.modern_adopt "2002-2015" 9999.modern_adopt "n.a." ///
	2.objektkat "Multi-family house" 3.objektkat "One-family house" 99.objektkat "n.a." ///
	2.anbietertyp "Banks" 4.anbietertyp "Agents" 5.anbietertyp "Private" ///
	1.postmai "PostApril" ///
	2.anbietertyp#1.postmai "Banks*PostApril" 4.anbietertyp#1.postmai "Agents*PostApril" ///
	0.objektzus "Yes" 1.objektzus "No" 99.objektzus "n.a." ///
	1.heizart "Central heating" 2.heizart "Floor heating" 3.heizart "Oven" 99.heizart "n.a." ///
	3.qualitaet "Superior" 4.qualitaet "Normal" 5.qualitaet "Basic"  99.qualitaet "n.a." ///
	grundflaeche "Lot size, in \$m^2\$" ///
	wohnflaeche "Living space, in \$m^2\$" ///
	zimmer_cont "\% of rooms" ///
	grundflaeche2 "Lot size (squared)" ///
	wohnflaeche2 "Living space (squared)" ///
	zimmer_cont2 "\# of rooms (squared)" ///
	_cons "Constant" ///
	) /// 
	drop(1900.baujahr_adopt 1900.modern_adopt 3.qualitaet 1.objektzus 1.heizart 5.anbietertyp) /* drop base categories */ ///
	order(1900.baujahr_adopt 1977.baujahr_adopt 2002.baujahr_adopt 9999.baujahr_adopt ///
	1900.modern_adopt 1977.modern_adopt 2002.modern_adopt 9999.modern_adopt ///
	3.qualitaet 4.qualitaet 5.qualitaet 99.qualitaet ///
	0.objektzus 1.objektzus 99.objektzus  ///
	1.heizart 2.heizart 3.heizart 99.heizart  ///
	2.anbietertyp 4.anbietertyp 5.anbietertyp ///
	1.postmai ///
	2.anbietertyp#1.postmai 4.anbietertyp#1.postmai ///
	2.objektkat 3.objektkat 99.objektkat ///
	grundflaeche grundflaeche2 ///
	wohnflaeche wohnflaeche2 ///
	zimmer_cont zimmer_cont2 ///
	_cons ///
	) ///
	replace

est drop disclosure


***
* Page 13: Kolmogorov-Smirnov test
***
ksmirnov evk ${ifnotlastmonth} & !missing(evk), by(postmai)




***
* Table 4, Panel (1): Estimates of the Effect of Energy Information Disclosure on House Prices (OLS)
***

* sample is the same as for the panel analyses
xtreg logkaufp epc $merkat_i $merkont ib1.objektzus ib5.anbietertyp i.monat if multlist > 0, fe 
est sto hedonic

estout hedonic, ///
	cells(b(fmt(3) star) se(fmt(3)) ci ) ///
	stats(N N_clust, fmt(%9.0fc %9.0fc)) ///
	varwidth(30) starlevels(* 0.05 ** 0.01) ///
	keep( *epc*) // style(tex)

	
***
* Table 6 (Online Appendix G): OLS Regression Results for Linear Probability Model (all parameter estimates)
***
estout hedonic, /// using "${TABLES}/$DATE_disclosure_appendix.txt", ///
	cells("b(star label(Coeff.) fmt(%12.2gc)) se(label(Std. Err.) fmt(%12.2gc))") ///
	starlevels(* 0.05 ** 0.01) ///
	stats(N, fmt(%12.0fc)) ///
	nobaselevels /// 
	varlabels( ///
	epc "EPC" ///
	1900.baujahr_adopt "1900-1976" 1977.baujahr_adopt "1977-2002" 2002.baujahr_adopt "2002-2015" 9999.baujahr_adopt "n.a." ///
	1900.modern_adopt "1900-1976" 1977.modern_adopt "1977-2001" 2002.modern_adopt "2002-2015" 9999.modern_adopt "n.a." ///
	2.objektkat "Multi-family house" 3.objektkat "One-family house" 99.objektkat "n.a." ///
	2.anbietertyp "Banks" 4.anbietertyp "Agents" 5.anbietertyp "Private" ///
	1.postmai "PostApril" ///
	2.anbietertyp#1.postmai "Banks*PostApril" 4.anbietertyp#1.postmai "Agents*PostApril" ///
	0.objektzus "Yes" 1.objektzus "No" 99.objektzus "n.a." ///
	1.heizart "Central heating" 2.heizart "Floor heating" 3.heizart "Oven" 99.heizart "n.a." ///
	3.qualitaet "Superior" 4.qualitaet "Normal" 5.qualitaet "Basic"  99.qualitaet "n.a." ///
	grundflaeche "Lot size, in \$m^2\$" ///
	wohnflaeche "Living space, in \$m^2\$" ///
	zimmer_cont "\# of rooms" ///
	grundflaeche2 "Lot size (squared)" ///
	wohnflaeche2 "Living space (squared)" ///
	zimmer_cont2 "\% of rooms (squared)" ///
	_cons "Constant" ///
	) /// 	
	drop(1900.baujahr_adopt 1900.modern_adopt 3.qualitaet 1.objektzus 1.heizart 5.anbietertyp *monat) /* drop base categories */ ///
	order(epc ///
	1900.baujahr_adopt 1977.baujahr_adopt 2002.baujahr_adopt ///	
	1900.modern_adopt 1977.modern_adopt 2002.modern_adopt 9999.modern_adopt ///	
	3.qualitaet 4.qualitaet 5.qualitaet 99.qualitaet ///
	0.objektzus 1.objektzus 99.objektzus  ///
	1.heizart 2.heizart 3.heizart 99.heizart  ///
	2.anbietertyp 4.anbietertyp 5.anbietertyp ///
	2.objektkat 3.objektkat 99.objektkat ///
	grundflaeche grundflaeche2 ///
	wohnflaeche wohnflaeche2 ///
	zimmer_cont ///
	_cons ///
	) ///
	replace
	
if ($LOGTIME == 1) log close




